<link rel="stylesheet" href="assets/store/css/goods.css?v=<?= $version ?>">
<link rel="stylesheet" href="assets/admin/plugins/umeditor/themes/default/css/umeditor.css">
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">员工个人信息</div>
                            </div>
<!--                            <div class="am-form-group">-->
<!--                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">员工类型 </label>-->
<!--                                <div class="am-u-sm-9 am-u-end">-->
<!--                                    <label class="am-radio-inline">-->
<!--                                        <input type="radio" name="company[type]" --><?//= $model['type']==1 ? 'checked' :""?><!-- onclick="getValue(1)" value="1" data-am-ucheck>-->
<!--                                        驻场人员-->
<!--                                    </label>-->
<!--                                    <label class="am-radio-inline">-->
<!--                                        <input type="radio" name="company[type]" --><?//= $model['type']==2 ? 'checked':""?><!-- onclick="getValue(2)" value="2" data-am-ucheck-->
<!--                                               >-->
<!--                                        置业顾问-->
<!--                                    </label>-->
<!--                                </div>-->
<!--                            </div>-->
                           <!-- <div class="am-form-group yyy" style=<?/*= $model['type']==1 ? "display:block" :"display:none"*/?>>
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">项目组 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="company[projectId]" required class="categoryName" id="categoryName">
                                        <option value="0" >请选择项目组</option>
                                        <?php /*if (isset($projectInfo)): foreach ($projectInfo as $first): */?>
                                            <option <?/*= $model['projectId'] == $first['id']? 'selected' : ""*/?> value="<?/*= $first['id'] */?>" > <?/*= $first['name'] */?></option>
                                        <?php /*endforeach; endif; */?>
                                    </select>
                                </div>
                            </div>

                            <div class="am-form-group zzz" style=<?/*= $model['type']==2 ? "display:block" :"display:none"*/?>>
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">驻场人员 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select name="company[zhuchangId]" required class="categoryName" id="categoryName">
                                        <option value="0" >请选择驻场</option>
                                        <?php /*if (isset($zhuchang)): foreach ($zhuchang as $first): */?>
                                            <option <?/*= $model['zhuchangId'] == $first['zhuchangId'] ? 'selected' : ""*/?> value="<?/*= $first['id'] */?>" > <?/*= $first['zhuchangName'].'-'.$first['name'] */?></option>
                                        <?php /*endforeach; endif; */?>
                                    </select>
                                </div>
                            </div>-->

                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">员工名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="company[name]"
                                           value="<?=$model['name']?>" required>
                                </div>
                            </div>
                            <div class="goods-spec-single">
                                <div class="am-form-group">
                                    <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">联系电话 </label>
                                    <div class="am-u-sm-9 am-u-end">
                                        <input class="tpl-form-input" name="company[phone]" type="text" id="username"   style="ime-mode:disabled;"  onpaste="return false;" onkeyup="displayResult()" maxlength="11"
                                               value="<?=$model['phone']?>" required>
                                    </div>
                                </div>
                            </div>
                          <!--  <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">小程序密码 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" readonly name="company[password]" value="<?/*=$model['password']*/?>" required>
                                </div>
                            </div>-->
                            <!-- 表单提交按钮 -->
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 图片文件列表模板 -->
{{include file="layouts/_template/tpl_file_item" /}}

<!-- 文件库弹窗 -->
{{include file="layouts/_template/file_library" /}}

<script src="assets/common/js/vue.min.js"></script>
<script src="assets/common/js/ddsort.js"></script>
<script src="assets/admin/plugins/umeditor/umeditor.config.js?v=<?= $version ?>"></script>
<script src="assets/admin/plugins/umeditor/umeditor.min.js"></script>
<script src="assets/store/js/goods.spec.js?v=<?= $version ?>"></script>
<script>
    function displayResult(){
        var name = $("#username").val();
        var nameValue = name.replace(/\D/g,'');
        $("#username").val(nameValue);
    }

    function getValue(obj){
        if(obj==1){
            $('.zzz').hide();
            $('.yyy').show();
        }else{
            $('.yyy').hide();
            $('.zzz').show();
        }
    }
    $(function () {
        //根据当前商户判断是否可以在顶级分类添加商品
        $('.categoryName').change(function(){
            var catId=$(this).val();
            $.ajax({
                url:'/index.php?s=/store/goods/canSelect',
                type:"POST",
                dataType:'json',
                data:{'catId':catId},
                success:function(res){
                    if(res.code==-1){
                        //将分类数据清空
                        $('select#categoryName').val(0);
                        layer.msg(res.msg)
                    }
                },
                error: function(res){

                }
            });
        })
        // 富文本编辑器
        UM.getEditor('container', {
            initialFrameWidth: 375 + 15,
            initialFrameHeight: 600
        });

        // 选择图片
        $('.upload-file').selectImages({
            name: 'company[licenseId]'
            , multiple: true
        });

        // 图片列表拖动
        $('.uploader-list').DDSort({
            target: '.file-item',
            delay: 100, // 延时处理，默认为 50 ms，防止手抖点击 A 链接无效
            floatStyle: {
                'border': '1px solid #ccc',
                'background-color': '#fff'
            }
        });

        // 切换单/多规格
        $('input:radio[name="goods[spec_type]"]').change(function (e) {
            var $goodsSpecMany = $('.goods-spec-many')
                , $goodsSpecSingle = $('.goods-spec-single');
            if (e.currentTarget.value === '10') {
                $goodsSpecMany.hide() && $goodsSpecSingle.show();
            } else {
                $goodsSpecMany.show() && $goodsSpecSingle.hide();
            }
        });

        // 注册商品多规格组件
        var specMany = new GoodsSpec({
            el: '#many-app'
        });
        //判断当前登录账号是否属于美妆，是则不能在顶级分类下添加商品

        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm({
            // 获取多规格sku数据
            buildData: function () {
                var specData = specMany.appVue.getData();
                return {
                    goods: {
                        spec_many: {
                            spec_attr: specData.spec_attr,
                            spec_list: specData.spec_list
                        }
                    }
                };
            },
            // 自定义验证
            validation: function () {
                var specType = $('input:radio[name="goods[spec_type]"]:checked').val();
                if (specType === '20') {
                    var isEmpty = specMany.appVue.isEmptySkuList();
                    isEmpty === true && layer.msg('商品规格不能为空');
                    return !isEmpty;
                }
                return true;
            }
        });

    });
</script>

